<template>
	<view class="page">
		<navigation textColor="#333333" barColor="#333333"defaultButton="back">服务评价</navigation>
		<view class="title">服务已完成</view>
		<view class="subtitle">请评价一下为您服务的义工吧</view>
		<view class="evaluate_title">评价义工</view>
		<view class="evaluate_rate">
			<uni-rate @input="rateChange" :size="30" :value="model.starNum" disabledColor="#f6a749" />
		</view>
		<view class="evaluate_select-panel">
			<view class="select_item" v-for="(item,index) in selectList" :key="index" @tap="statusChange(index,item.isActive)"
			 :class="{'active': item.isActive && !item.isBad,'bod': item.isBad,'bodIsActive': item.isActive && item.isBad}"><text>{{item.label}}</text></view>
		</view>
		<view class="idea_panel">
			<textarea class="idea" v-model="model.content" placeholder="写其他意见和建议" />
		</view>
		<button class="page_btn" hover-class="page_btn-hover" @tap="evaluate">发表评价</button>
	</view>
</template>

<script>
	import * as userServeApi from '@/api/userApi/serve.js';
	import {
		uniRate
	} from '@dcloudio/uni-ui'
	export default {
		components: {
			uniRate
		},
		data() {
			return {
				model: {
					starNum: 0,
					judgeProposal: [],
					content: '',
				},
				selectList: [{
						isBad: false,
						isActive: false,
						label: "服务态度好"
					},
					{
						isBad: false,
						isActive: false,
						label: "速度快"
					},
					{
						isBad: false,
						isActive: false,
						label: "义工专业知识很全"
					},
					{
						isBad: false,
						isActive: false,
						label: "准时到达"
					},
					{
						isBad: false,
						isActive: false,
						label: "不错"
					},
					{
						isActive: false,
						label: "装备很齐全"
					},
					{
						isBad: false,
						isActive: false,
						label: "干净卫生"
					},
					{
						isBad: true,
						isActive: false,
						label: "态度不好"
					},
					{
						isBad: true,
						isActive: false,
						label: "不专业"
					},
					{
						isBad: true,
						isActive: false,
						label: "义工未按时到达"
					}
				]
			};
		},
		methods: {
			rateChange(event) {
				this.$set(this.model, "starNum", event);
			},
			statusChange(index, status) {
				this.$set(this.selectList[index], "isActive", !status);
				let array = [];
				this.selectList.map(item=> {
					if(item.isActive) array.push(item.label);
				});
				this.model.judgeProposal = array;
			},
			evaluate() {
				if(this.id) {
					this.model.orderId = this.id;
					userServeApi
						.addJudged(this.model)
						.then(res => { 
							uni.reLaunch({
								url: `/pages/mine/order/order?type=待评价`
							});
						})
						.catch(e => {
							uni.showToast({
								title: e.msg,
								icon: 'none',
								duration: 1000
							});
						});
				} else {
					uni.showToast({
						title: '订单异常！',
						icon: 'none',
						duration: 1000
					});
				}
				
			}
		},
		onLoad(options) {
			if (options && options.id) {
				this.id = options.id;
			}
		}
	}
</script>

<style lang="stylus">
	.title {
		font-size: 42rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FB7B22;
		padding-top 100rpx;
		line-height: 48rpx;
		text-align center;
	}

	.subtitle {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #999999;
		line-height: 48rpx;
		margin-top 30rpx;
		position relative;
		text-align center;

		&::after {
			content '';
			position absolute;
			bottom -40rpx;
			left 86rpx;
			right 86rpx;
			height 2rpx;
			background-color rgba(229, 229, 229, 1);
		}
	}

	.evaluate_title {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #999999;
		margin-top 80rpx;
		text-align center;
	}

	.evaluate_rate {
		margin-top 40rpx;
		display flex;
		justify-content center;
	}

	.evaluate_select-panel {
		width 100%;
		display flex;
		flex-wrap wrap;
		justify-content space-between;
		padding 65rpx 35rpx;
		box-sizing border-box;

		.select_item {
			padding 3rpx 30rpx;
			height: 55rpx;
			display flex;
			align-items center;
			justify-content center;
			border-radius 28rpx;
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #FF4200;
			text-align center;
			background-color rgba(255, 66, 0, 0.14);
			margin-bottom 30rpx;

			&:nth-of-type(1),
			&:nth-of-type(8) {
				margin-left 35rpx;
			}

			&:nth-of-type(3),
			&:nth-of-type(10) {
				margin-right 35rpx;
			}
		}

		.active {
			color #FFFFFF;
			background-color rgba(251, 123, 34, 1);
		}
		.bod {
			color rgba(102, 102, 102, 1);
			background-color rgba(0, 0, 0, 0.08);
		}
		.bodIsActive {
			color #FFFFFF;
			background-color rgba(0, 0, 0, 0.62);
		}
	}
	.idea_panel {
		width 100%;
		padding 0rpx 30rpx;
		box-sizing border-box;
		height 280rpx;
		.idea {
			width 100%;
			height 100%;
			padding 20rpx;
			box-sizing border-box;
			background-color rgba(244, 244, 244, 1);
		}
	}
	.page_btn {
		position absolute;
		bottom 30rpx;
		right 30rpx;
		left 30rpx;
	}
</style>
